package com.bwstudio.demo.consumer.service;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.springframework.web.context.request.async.DeferredResult;

public class DeferredResultQueue {

    //队列
    private static Queue<DeferredResult<String>> deferredResultQueue = new ConcurrentLinkedQueue<>();

    /**
     * 添加DeferredResult进队列
     * @param deferredResult
     */
    public static void save(DeferredResult<String> deferredResult) {
        deferredResultQueue.add(deferredResult);
    }

    /**
     * 从队列中取出第一个元素并删除
     * @return
     */
    public static DeferredResult<String> get() {
        return deferredResultQueue.poll();
    }
}
